//package com.example.interceptor;
//
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.session.Session;
//import org.apache.shiro.subject.Subject;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import java.io.PrintWriter;
//
///**
// * @Author: 胡成
// * @Version: 0.0.1V
// * @Date: 2019/3/18
// * @Description: 类描述
// **/
//public class MyInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
//        Subject subject = SecurityUtils.getSubject();
//        Session session = subject.getSession();
//        System.out.println(session.getAttribute("userinfo"));
//        System.out.println(request.getRequestURI());
//        if (session.getAttribute("userinfo") == null) {
//            response.setCharacterEncoding("utf-8");
//            PrintWriter printWriter = response.getWriter();
//            response.setStatus(429);
//            printWriter.write("{\"result\":\"用户未登录或登录超时，请重新登录!\"}");
//            response.setContentType("text/html;charset=utf-8");
//            return false;
//        }
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
//    }
//}
